﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Xml.Linq;
using System.Collections.Generic;
using LUStationery.Model;
using LUStationery.DAO;

namespace LUStationery.Controller
{
    public class PositionListControl
    {
        public PositionList getPosition()
        {
            PositionDAO pDAO = new PositionDAO();
            IDataReader idr = pDAO.getPosition();
            return PositionListControl.convertIdrToPositionList(idr);
        }

        public PositionList getPositionsByDepartment(string deptCode)
        {
            PositionDAO pDAO = new PositionDAO();
            IDataReader idr = pDAO.getPositionByDepartment(deptCode);
            return PositionListControl.convertIdrToPositionList(idr);
        }

        protected static Position convertIdrToPosition(IDataReader idr)
        {
            Position p = new Position();
            while (idr.Read())
            {
                p.PositionDesc = Convert.ToString(idr["position"]);
                break;
            }
            return p;
        }

        protected static PositionList convertIdrToPositionList(IDataReader idr)
        {
            PositionList pList = new PositionList();
            while (idr.Read())
            {
                Position p = new Position();
                p.PositionDesc = Convert.ToString(idr["position"]);
                pList.Add(p);
            }
            return pList;
        }

    }
}
